package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.http.HttpResponse;
import com.banshuibao.bsb_android.http.HttpUtil;
import com.banshuibao.bsb_android.model.InforDetailsRequestModel;
import com.banshuibao.bsb_android.model.SystemInformationModel;
import com.banshuibao.bsb_android.util.TimeUtil;
import com.banshuibao.bsb_android.util.WebViewCssUtil;

public class SystemIformationDetailsActivity extends BaseActivity {

    private TextView title,date;
    private WebView webView;
    private int id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_iformation_details);
        id = getIntent().getIntExtra("id",0);
        initView();
        requestNet();
    }

    public void initView(){
        setTitleText("内容");
        title = findViewById(R.id.title);
        title.getPaint().setFakeBoldText(true);
        date = findViewById(R.id.date);
        webView = findViewById(R.id.webView);
    }

    public void requestNet(){
        InforDetailsRequestModel model = new InforDetailsRequestModel();
        model.setId(id);
        HttpUtil.doPost(Constants.Url.INFORMATION_DETAILS,model, new HttpResponse(this, SystemInformationModel.class) {
            @Override
            public void onResult(Object obj) {
                SystemInformationModel dataBean = (SystemInformationModel) obj;
                SystemInformationModel.DataBean data = dataBean.getData();
                title.setText(data.getTitle());
                date.setText(TimeUtil.format2(data.getPublishTime()));
                String newHtml = WebViewCssUtil.setCss(data.getContent());
                webView.loadDataWithBaseURL(null, newHtml, "text/html", "utf-8", null);
            }
        });
    }
}
